<?php
namespace app\common\model;
use think\Config;
use think\Db;
use think\Model;

class Car extends Model{

    protected $table = "jiujiu_car";

    public function getUserCar($uid){
        $data = Db::table('jiujiu_car')
            ->field(['jiujiu_car.*','jiujiu_product.title','jiujiu_product.salePrice','jiujiu_product.img'])
            ->join('jiujiu_product','jiujiu_product.id=jiujiu_car.productId','LEFT')
            ->where('jiujiu_car.uid',$uid)
            ->select();
        return $data;
    }

    public function addUserCar($productId,$shopId,$uid){
        $car = $this->where('productId',$productId)
            ->where('shopId',$shopId)
            ->where('uid',$uid)
            ->find();
        if($car){
            $car->num = 1+ $car->num;
            $car->save();
        }
        else{
            $this->insert([
                'productId'=>$productId,
                'shopId'=>$shopId,
                'uid'=>$uid,
                'createTime'=>time(),
            ]);
        }

    }




}